package jdk8;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author xiaoming
 * @version 1.0
 * @date 2019-05-06 17:06
 **/
public class MethodReference {
    public static void main(String[] args) {
        // 构造器引用
        final Car car = Car.create(Car::new);
        final List<Car> cars = Arrays.asList(car);

        // 静态方法引用
       // cars.forEach(Car::collide);
        //cars.forEach(car1 -> System.out.println(car1));

        // 特定类的任意对象的方法调用
        cars.forEach(Car::repair);

        // 特定对象的方法引用
        final Car police = Car.create(Car::new);


    }

}

class Car {
    public static Car create(final Supplier<Car> supplier) {
        return supplier.get();
    }

    public static void collide(final Car car) {
        System.out.println("Collide: " + car.toString());
    }

    public void follow(final Car another) {
        System.out.println("Following the : " + another.toString());
    }

    public void repair() {
        System.out.println("Repaired" + this.toString());
    }
}
